package com.luoying.itew.dialog;

import android.app.Dialog;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.luoying.itew.R;
import com.luoying.itew.adapter.PointsListAdapter;
import com.luoying.itew.bean.MonitorBean;

import java.util.List;

/**
 * Created by lufan on 2018/5/31
 * Class describe 点击查看监测详情集合
 */
public class PointsListDialog extends Dialog implements
        PointsListAdapter.OnItemClickListener {
    private RecyclerView recyclerView;
    private TextView titleView;
    private PointsListAdapter adapter;
    private PointsDialogClickListener listener;

    public PointsListDialog(@NonNull Context context,List<MonitorBean> list) {
        super(context, R.style.collector_dig_style);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_points_list, null);
        setContentView(view);
        recyclerView =  view.findViewById(R.id.points_rv);
        titleView =  view.findViewById(R.id.points_title);
        adapter = new PointsListAdapter(list);
        adapter.setListener(this::onClick);
        recyclerView.setAdapter(adapter);
        if(list.isEmpty()){
            titleView.setText("当前街道没有监测点");
        } else {
            titleView.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(MonitorBean bean) {
        if(listener!=null){
            listener.OnClick(bean);
            this.dismiss();
        }
    }

    public void setListener(PointsDialogClickListener listener) {
        this.listener = listener;
    }

    public interface PointsDialogClickListener{
        void OnClick(MonitorBean bean);
    }
}
